package com.his.registration.controller;

import com.his.common.Result;
import com.his.dto.CheckResult;
import com.his.registration.pojo.CheckRequest;
import com.his.registration.service.CheckRequestService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/6 11:42
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/check")
public class CheckRequestController {
    @Autowired
    private CheckRequestService checkRequestService;

    //开设检查单
    @RequestMapping("/insert")
    public Result insert(int registerId, int medicalTechnologyId, String checkState){
        //获取当前时间
        LocalDateTime creationTime = LocalDateTime.now();
        int result = checkRequestService.insert(registerId, medicalTechnologyId, creationTime, checkState);
        //获取刚刚插入的检查id
        int insertId = checkRequestService.getInsertId();
        return Result.success(insertId);
    }

    //根据检查id查询
    @RequestMapping("/selectById")
    public Result selectById(int id){
        CheckRequest checkRequest = checkRequestService.selectById(id);
        return Result.success(checkRequest);
    }

    //在得到id的基础上添加其他数据
    @RequestMapping("/updateOthers")
    public Result updateOthers(int id,String checkInfo,String checkPosition,String checkRemark){
        int result = checkRequestService.updateOthers(id,checkInfo, checkPosition, checkRemark);
        return Result.success(result+"条检查更新成功");
    }

    //根据id删除
    @RequestMapping("/deleteById")
    public Result deleteById(int id){
        int result = checkRequestService.deleteById(id);
        return Result.success("成功在检查表中删除"+result+"条数据");
    }

    //搜索挂号id对应的检查结果信息
    @RequestMapping("/getCheckByRegisterId")
    public Result getCheckByRegisterId(int registerId){
        List<CheckResult> checkResultList = checkRequestService.getCheckByRegisterId(registerId);
        return Result.success(checkResultList);
    }
}
